package com.alquiler.dao;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.alquiler.dto.ItemDto;
import com.alquiler.entities.Empleado;
import com.alquiler.implementation.GenericDaoImpl;

public class EmpleadoDao extends GenericDaoImpl<Empleado, Integer, ItemDto>{

	public EmpleadoDao(EntityManager entityManager) {
		super(entityManager);	
	}
	
	
	public Empleado getEmpleadoByCredencials(String username, String password){
		
		try {			
			Query query  =  entityManager.createQuery("Select e FROM "+ Empleado.class.getCanonicalName()+" e "
					+ "where e.userName = :username and e.password = :password");
			 
			query.setParameter("username",username);		
			query.setParameter("password",password);	
		
			Empleado result = (Empleado) query.getSingleResult();
			return result; 
		} catch (Exception e) {
			
			return null;
		}
		
	}

	 public Empleado getEmpleadoByIdentificacion(String identificacion){
		
		try {			
			Query query  =  entityManager.createQuery("Select e FROM "+ Empleado.class.getCanonicalName()+" e "
					+ "where e.identificacion = :identi")
					.setParameter("identi",identificacion);
				
			Empleado resultList = (Empleado) query.getSingleResult();
			return resultList; 
		} catch (Exception e) {
			
			return null;
		}
		
	}

}
